/*
 *  Copyright (C) 2010 Francesco Boffa (aka AlfaOmega08)
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package ImageFormats;

import java.io.*;
import java.util.*;

public class TreeElement {
	private TreeElement Parent;
	private Vector<TreeElement> Childs = new Vector<TreeElement>();
	private Boolean Directory;
	private Boolean Root;
	private String Name;
	private long Sector;
	private int Size;

	public TreeElement(String n, TreeElement p, Boolean d, Boolean r, long se, int s) {
		Name = new String(n);
		Parent = p;
		Directory = d;
		Root = r;
		Sector = se;
		Size = s;
	}

	public void AddChild(TreeElement e) {
		Childs.add(e);
	}

	public TreeElement getChild(String n) throws FileNotFoundException {
		if (n.equals(new String("."))) {
			return this;
		} else if (n.equals(new String(".."))) {
			return Parent;
		}

		for (int i = 0; i < Childs.size(); i++) {
			if (n.equals(Childs.get(i).getName())) {
				return Childs.get(i);
			}
		}

		throw new FileNotFoundException("The file do not exist");
	}

	public Vector<TreeElement> getChilds() {
		return Childs;
	}

	public String getName() {
		return Name;
	}

	public int getSize() {
		return Size;
	}

	public long getDataSector() {
		return Sector;
	}

	public Boolean isDirectory() {
		return Directory;
	}

	public Boolean isRoot() {
		return Root;
	}
}
